import { useAsyncPost } from "#imports";

interface LoginParams {
  username: string;
  password: string;
  type?: string;
  sessionToken?: string;
}

interface LoginResponse {
  tokenType: string;
  expiresIn: number;
  accessToken: string;
  refreshToken: string;
  isMissNickname: boolean;
  avatarUrl: string;
  userStatus: number;
  userId: number;
}

export const doLogin = (user: LoginParams) => {
  const inst = useAsyncPost<LoginResponse>(
    "/users/username.login",
    "user-login",
    user,
    {
      server: false,
      immediate: false
    }
  );
  // Force pending to false
  inst.pending.value = false;
  return inst;
};
